package com.itheima.nio.buffer.demo03;

import java.nio.ByteBuffer;

public class ByteBufferDemo03 {

    public static void main(String[] args) {

        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
        System.out.println(byteBuffer);

        String s = "abcdef";
        byte[] bytes = s.getBytes();
        byteBuffer.put(bytes);
        System.out.println(byteBuffer);

        byteBuffer.flip();
        System.out.println(byteBuffer);

        System.out.println(byteBuffer.get());
        System.out.println(byteBuffer);
        System.out.println(byteBuffer.get(3));
        System.out.println(byteBuffer);
        byteBuffer.rewind();
        System.out.println(byteBuffer.get(new byte[byteBuffer.limit()]));
        System.out.println(byteBuffer);
    }
}
